<?php
	session_start();
	include_once("../../service/productService.php");
	$products = getLikeOfUser(isset($_SESSION["userid"])?$_SESSION["userid"]:0);
 ?>
<?php
	while($product = mysql_fetch_array($products)){
	   $images = findImagesOfProduct($product["PRO_ID"]);
		if(mysql_num_rows($images) > 0){
			$firstImg = mysql_fetch_array($images); 
?> 
                <div class="favourite-product-wrapper">
                	<div class="favourite-product-sep"></div>
                	<img src="./image/product/<?php echo $product["PRO_ID"]."/thumbnail/".$firstImg["IMG_PATH"]; ?>"/>
                    <div class="favourite-product-delete-wrapper">
                    	<div onclick="unlikeProduct(<?php echo $product["PRO_ID"]; ?>,<?php echo $_SESSION["userid"]; ?>);"></div>
                    </div>
                    <a href="./product-detail.php?product=<?php echo $product["PRO_ID"]; ?>">
                        <div class="favourite-product-info-wrapper">
                        	<div class="favourite-product-name">
                            	 <?php echo $product["PRO_NAME"]; ?>
                            </div>
                            <div class="favourite-product-price vn-currency"><?php echo number_format($product["PRO_PRICE"]); ?></div>
                            <div class="favourite-product-discounted-price vn-currency"><?php echo number_format(getDiscountedAndOptionalPriceOfProduct($product["PRO_ID"])); ?></div>
                        </div>
                    </a>
                </div>
<?php
        }else{
?>
                <div class="favourite-product-wrapper">
                	<div class="favourite-product-sep"></div>
                	<img src="./image/product/no-image.jpg"/>
                    <div class="favourite-product-delete-wrapper">
                    	<div onclick="unlikeProduct(<?php echo $product["PRO_ID"]; ?>,<?php echo $_SESSION["userid"]; ?>);"></div>
                    </div>
                    <a href="./product-detail.php?product=<?php echo $product["PRO_ID"]; ?>">
                        <div class="favourite-product-info-wrapper">
                        	<div class="favourite-product-name">
                            	 <?php echo $product["PRO_NAME"]; ?>
                            </div>
                            <div class="favourite-product-price"><?php echo number_format($product["PRO_PRICE"]); ?></div>
                            <div class="favourite-product-discounted-price"><?php echo number_format(getDiscountedAndOptionalPriceOfProduct($product["PRO_ID"])); ?></div>
                        </div>
                    </a>
                </div>
<?php
		}
?>
<?php
	}
?>
<script>
    $(".favourite-product-price").each(function(){
        $(this).html(formatCurrency($(this).html(),0)); 
    });
</script>